package org.java.api.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author WHQ
 * @version 1.0
 * @date 2022-3-27 0027 下午 7:39
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * //配置docket以配置Swagger具体参数
     * @return
     */
    @Bean
    public Docket getDocket(@Qualifier("getApiInfo") ApiInfo apiInfo){
        //docket关联文档信息
        return new Docket(DocumentationType.SWAGGER_2).
                apiInfo(apiInfo)
                .select()//通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("org.java.api"))
                .build();
    }

    /**
     * 配置文档信息
     * @return
     */
    @Bean
    public ApiInfo getApiInfo(){
        //String name, String url, String email,配置用户信息
        Contact contact=new Contact("喻国志","http://www.baidu.com","121212@qq.com");
        //String title, String description,
        // String version, String termsOfServiceUrl, Contact contact,
        // String license, String licenseUrl,
        // Collection<VendorExtension> vendorExtensions
        return new ApiInfo(
            "swagger学习",//标题
                "学习演示如何配置Swagger",
                "v1.0",//版本
                "http://www.apache.org",//组织地址
                contact,//联系人
                "Apach 2.0 许可",//许可
                "http://www.apache.org",//许可连接
                new ArrayList<>()//扩展
        );
    }
}
